package com.xiaotu.controller;

import com.xiaotu.pojo.Dept;
import com.xiaotu.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Controller
public class DeptConsumerController {
   /* @Autowired
    private RestTemplate restTemplate;*/
    //Ribbon 我们这里的地址应该是一个变量,通过服务名来访问

    @Autowired
    private DeptClientService deptClientServicel;

    @RequestMapping(path = "/dept/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Dept getDeptById(@PathVariable("id") Integer id){
        return deptClientServicel.queryById(id);
    }
    @RequestMapping(path = "/dept",method = RequestMethod.POST)
    @ResponseBody
    public Boolean addDept(Dept dept){
        return deptClientServicel.addDept(dept);
    }
    @RequestMapping(path = "/dept",method = RequestMethod.GET)
    @ResponseBody
    public List<Dept> deptList(){
        return deptClientServicel.queryAll();
    }
}
